home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume3 / libc_term < prev    next >
Encoding:
Internet Message Format  |  1986-11-30  |  35.0 KB

  1. From: "George W. Sherouse" <seismo!unc.CSNET!godot!sherouse>
  2. Subject: libc_term - datum entry using curses
  3. Newsgroups: mod.sources
  4. Approved: jpn@panda.UUCP
  5.  
  6. Mod.sources:  Volume 3, Issue 101
  7. Submitted by: "George W. Sherouse" <seismo!unc.CSNET!godot!sherouse>
  8.  
  9.  
  10. Here is a library of bullet-proof datum-entry routines that has
  11. gotten a fair bit of use here and elsewhere.  It was posted to
  12. net.sources quite awhile ago.
  13.  
  14. - George
  15. <decvax!mcnc!godot!sherouse>
  16.  
  17. --------------------------  cut here ------------------------
  18. #! /bin/sh
  19. # This is a shell archive, meaning:
  20. # 1. Remove everything above the #! /bin/sh line.
  21. # 2. Save the resulting text in a file.
  22. # 3. Execute the file with /bin/sh (not csh) to create the files:
  23. #    README
  24. #    Makefile
  25. #    c_term.l
  26. #    c_term.h
  27. #    center.c
  28. #    examp.c
  29. #    get_bool.c
  30. #    get_erase.c
  31. #    get_float.c
  32. #    get_hosp_num.c
  33. #    get_int.c
  34. #    get_string.c
  35. #    init_term.c
  36. #    pick_one.c
  37. # This archive created: Sat Jan 25 11:54:18 1986
  38. export PATH; PATH=/bin:$PATH
  39. echo shar: extracting "'README'" '(777 characters)'
  40. if test -f 'README'
  41. then
  42.     echo shar: will not over-write existing file "'README'"
  43. else
  44. sed 's/^    X//' << \SHAR_AND_ENJOY > 'README'
  45.     XThis directory contains the source for a library (libc_term) of
  46.     Xbullet-proof datum-entry routines that sit on top of curses.  Another
  47.     Xversion exists which uses termcap directly (libterm).
  48.     X
  49.     XThe code is rather a mess and in some cases rather inefficient.  That
  50.     Xis a statement not an apology.  This was some of my first C code and
  51.     Xhas been used extensively here and elsewhere with *NO* bug reports.
  52.     XThis same code was posted to net.sources about 18 months ago and a
  53.     Xtrickle of requests has continued since then.  If it ain't broke don't
  54.     Xfix it.
  55.     X
  56.     XPermission is granted to copy and redistribute this code as long as no
  57.     Xmoney changes hands and this notice and the authorship notes remain
  58.     Xintact.  Let me know if you find/fix any bugs.  Enjoy.
  59.     X
  60.     X- George
  61.     X<decvax!mcnc!godot!sherouse>
  62.     X
  63. SHAR_AND_ENJOY
  64. if test 777 -ne "`wc -c < 'README'`"
  65. then
  66.     echo shar: error transmitting "'README'" '(should have been 777 characters)'
  67. fi
  68. fi # end of overwriting check
  69. echo shar: extracting "'Makefile'" '(956 characters)'
  70. if test -f 'Makefile'
  71. then
  72.     echo shar: will not over-write existing file "'Makefile'"
  73. else
  74. sed 's/^    X//' << \SHAR_AND_ENJOY > 'Makefile'
  75.     XCFLAGS = -O
  76.     XLIBDIR = /usr/local/lib
  77.     XMANDIR = /usr/man/manl
  78.     XINCDIR = /usr/include
  79.     X
  80.     XOBJS = init_term.o get_erase.o get_float.o get_int.o\
  81.     X    get_bool.o get_hosp_num.o get_string.o pick_one.o\
  82.     X    center.o
  83.     X
  84.     Xlibc_term.a: $(OBJS) Makefile
  85.     X    ar rcv libc_term.a $(OBJS)
  86.     X    ranlib libc_term.a
  87.     X
  88.     Xinit_term.o: init_term.c c_term.h Makefile
  89.     Xget_erase.o: get_erase.c c_term.h Makefile
  90.     Xget_float.o: get_float.c c_term.h Makefile
  91.     Xget_int.o: get_int.c c_term.h Makefile
  92.     Xget_bool.o: get_bool.c c_term.h Makefile
  93.     Xget_hosp_num.o: get_hosp_num.c c_term.h Makefile
  94.     Xget_string.o: get_string.c c_term.h Makefile
  95.     Xpick_one.o: pick_one.c c_term.h Makefile
  96.     Xcenter.o: center.c c_term.h Makefile
  97.     X
  98.     Xexamp: examp.c c_term.h /usr/local/lib/libc_term.a Makefile
  99.     X    cc $(CFLAGS) -o examp examp.c -lc_term -lcurses -ltermcap
  100.     X
  101.     Xinstall: libc_term.a
  102.     X    mv libc_term.a $(LIBDIR)
  103.     X    ranlib $(LIBDIR)/libc_term.a
  104.     X    cp c_term.h $(INCDIR)
  105.     X
  106.     Xinstall_man: c_term.l
  107.     X    cp c_term.l $(MANDIR)
  108.     X
  109.     Xclean:
  110.     X    rm -f *.o a.out core
  111. SHAR_AND_ENJOY
  112. if test 956 -ne "`wc -c < 'Makefile'`"
  113. then
  114.     echo shar: error transmitting "'Makefile'" '(should have been 956 characters)'
  115. fi
  116. fi # end of overwriting check
  117. echo shar: extracting "'c_term.l'" '(3585 characters)'
  118. if test -f 'c_term.l'
  119. then
  120.     echo shar: will not over-write existing file "'c_term.l'"
  121. else
  122. sed 's/^    X//' << \SHAR_AND_ENJOY > 'c_term.l'
  123.     X.TH C_TERM L "Radiation Oncology, NCMH"
  124.     X.UC 4
  125.     X.SH NAME
  126.     Xc_term \- "crash-proof" datum-entry routines for curses(3x)
  127.     X.SH SYNOPSIS
  128.     X#include <curses.h>
  129.     X.br
  130.     X#include <c_term.h>
  131.     X.br
  132.     X.B cc
  133.     X[ flags ] files
  134.     X.B \-lc_term \-lcurses \-ltermcap
  135.     X[ libraries ]
  136.     X.SH DESCRIPTION
  137.     XThese routines look after datum-entry through stdscr for the basic datum
  138.     Xtypes.
  139.     XAn initial call to
  140.     X.I init_term
  141.     Xinitializes the curses package by calling
  142.     X.I initscr, raw, and noecho,
  143.     Xand initializes 
  144.     X.I c_term
  145.     Xby fetching the terminal's erase character.
  146.     XIn typical use, the calling program would paint a screen
  147.     Xand place the cursor at the beginning of a datum field
  148.     Xusing 
  149.     X.I curses(3x)
  150.     Xand would then call the appropriate 
  151.     X.I c_term
  152.     Xroutine to enter or edit that datum.
  153.     XThe field is highlighted using standout mode and the default value, if any,
  154.     Xis displayed.
  155.     XThe user may then enter a new value of the datum under strict field size
  156.     Xenforcement or accept the default.
  157.     XAcceptance of the displayed value is indicated by a RETURN.
  158.     XThe default value can be retrieved by ^X.
  159.     XThe program can be aborted by a character which is defined at installation of
  160.     Xthe library.
  161.     XIf ABORT_CHAR is not defined, no abort is possible.
  162.     XWhen the value is accepted, the field is rewritten in normal mode and with the
  163.     Xnew value of the datum, and the cursor is left at the end of the field.
  164.     X
  165.     XExceptions to the above are
  166.     X.I get_bool
  167.     Xfor which valid inputs are n, N, y, Y, SPACE, and RETURN, for
  168.     Xno, yes, toggle, and accept respectively,
  169.     Xand
  170.     X.I pick_one
  171.     Xwhich understands ^ for previous value, SPACE for next value, and RETURN
  172.     Xfor accept.
  173.     X
  174.     XThe user is still responsible for the
  175.     X.I endwin()
  176.     Xbefore exiting.
  177.     X.SH SEE ALSO
  178.     Xcurses(3x)
  179.     X.SH AUTHOR
  180.     X.nf
  181.     XGeorge W. Sherouse
  182.     XRadiation Oncology
  183.     XNorth Carolina Memorial Hospital
  184.     XUniversity of North Carolina, Chapel Hill
  185.     X.SH FUNCTIONS
  186.     X.nf
  187.     XInitialize curses and c_term.
  188.     X    void init_term();
  189.     X
  190.     XGet a floating point number.  Imagine %(field_width).(places)f
  191.     Xin a printf.
  192.     X    float get_float(default, field_width, places);
  193.     X    float default;
  194.     X    int field_width;
  195.     X    int places;
  196.     X
  197.     XGet an integer.
  198.     X    int get_int(default, field_width);
  199.     X    int default;
  200.     X    int field_width;
  201.     X
  202.     XGet a boolean.
  203.     X    int get_bool(default);
  204.     X    int default;
  205.     X
  206.     XGet a hospital number in the format 00-00-00.
  207.     X    void get_hosp_num(hosp_num);
  208.     X    char *hosp_num
  209.     X
  210.     XGet a string.  String should be at least field_size + 1 long
  211.     Xto accomodate the appended null.  Null_ok is a boolean which
  212.     Xdeclares whether or not a string of length zero is acceptable.
  213.     X    void get_string(string, field_size, null_ok);
  214.     X    char *string;
  215.     X    int field_size;
  216.     X    int null_ok;
  217.     X
  218.     XPick one string from a list of strings.
  219.     X    int pick_one(list, choice_count);
  220.     X    char **list;
  221.     X    int choice_count;
  222.     X
  223.     XPrint string centered on line.  Mode is a boolean which requests
  224.     Xstandout mode if TRUE.
  225.     X    void center(line, string, mode);
  226.     X    int line;
  227.     X    char *string;
  228.     X    int mode;
  229.     X.SH BUGS
  230.     XMany sorts of stupidity are not checked for.
  231.     XThese include but are not limited to string longer than COLS in
  232.     X.I center,
  233.     Xfractional part longer than field_size in
  234.     X.I get_float,
  235.     Xand 0 or negative field_size anywhere.
  236.     X
  237.     X.I Get_float
  238.     Xdoes not support scientific notation.
  239.     XIt also does not let you back up over the decimal point once it has placed
  240.     Xit.
  241.     XThis is no great hardship since you can always ^X to restart.
  242.     X
  243.     XStandout mode as implemented in
  244.     X.I curses(3x)
  245.     Xis not reliable.
  246.     XTry it on a terminal with magic cookies.
  247.     X
  248.     XSome of the code is a little ugly, having been hacked unmercifully through many
  249.     Xrevisions.
  250.     XIn particular, this
  251.     X.I curses
  252.     Xcompatible version is actually a hacked subset of a version which
  253.     Xtalks to
  254.     X.I termcap(3x)
  255.     Xdirectly.
  256.     XIt does seem to work, though.
  257. SHAR_AND_ENJOY
  258. if test 3585 -ne "`wc -c < 'c_term.l'`"
  259. then
  260.     echo shar: error transmitting "'c_term.l'" '(should have been 3585 characters)'
  261. fi
  262. fi # end of overwriting check
  263. echo shar: extracting "'c_term.h'" '(203 characters)'
  264. if test -f 'c_term.h'
  265. then
  266.     echo shar: will not over-write existing file "'c_term.h'"
  267. else
  268. sed 's/^    X//' << \SHAR_AND_ENJOY > 'c_term.h'
  269.     X#define ABORT_CHAR ('\03')
  270.     X
  271.     Xvoid    init_term();
  272.     Xchar    get_erase();
  273.     Xfloat    get_float();
  274.     Xint    get_int();
  275.     Xint    get_bool();
  276.     Xvoid    get_hosp_num();
  277.     Xvoid    get_string();
  278.     Xint    pick_one();
  279.     Xvoid    center();
  280.     X
  281.     Xchar    erase_char;
  282. SHAR_AND_ENJOY
  283. if test 203 -ne "`wc -c < 'c_term.h'`"
  284. then
  285.     echo shar: error transmitting "'c_term.h'" '(should have been 203 characters)'
  286. fi
  287. fi # end of overwriting check
  288. echo shar: extracting "'center.c'" '(1482 characters)'
  289. if test -f 'center.c'
  290. then
  291.     echo shar: will not over-write existing file "'center.c'"
  292. else
  293. sed 's/^    X//' << \SHAR_AND_ENJOY > 'center.c'
  294.     X#include <strings.h>
  295.     X#include <curses.h>
  296.     X#include "c_term.h"
  297.     X
  298.     Xvoid center(line, string, mode)
  299.     Xint line;
  300.     Xchar *string;
  301.     Xint mode;
  302.     X
  303.     X/*
  304.     X ---------------------------------------------------------------------------
  305.     X 
  306.     X   Last revision - 
  307.     X    6 January 1985 - GWS
  308.     X    Change to use curses
  309.     X
  310.     X     2 April 1984 - GWS
  311.     X 
  312.     X 
  313.     X   NAME
  314.     X     center - center string in sceen
  315.     X 
  316.     X   SYNOPSIS
  317.     X    void center(line, string, mode)
  318.     X    int line;
  319.     X    char *string;
  320.     X    int mode;
  321.     X 
  322.     X   DESCRIPTION
  323.     X    This routine uses the curses(3x) routines to center and
  324.     X    optionally emphasize a string.  'Line' is the terminal line
  325.     X    number on which the string is to be placed, numbered starting
  326.     X    with 0.  'Mode' takes one of three values:
  327.     X        0 - no control characters sent
  328.     X        1 - stand-out mode turned on before and off after 'string'
  329.     X        2 - stand-out mode turned on before and off after 'string'
  330.     X    A call to init_term must be made before the first call to center.
  331.     X 
  332.     X   SEE ALSO
  333.     X    curses(3x), init_term
  334.     X 
  335.     X   DIAGNOSTICS
  336.     X    none 
  337.     X 
  338.     X   BUGS
  339.     X    does not check for string too long to fit on one line 
  340.     X 
  341.     X   AUTHOR
  342.     X     George W. Sherouse
  343.     X     31 March 1984
  344.     X 
  345.     X ---------------------------------------------------------------------------
  346.     X*/
  347.     X
  348.     X{
  349.     X    int col;
  350.     X
  351.     X    int strlen();
  352.     X
  353.     X    col = (COLS - strlen(string)) / 2 - 1;
  354.     X    switch (mode)
  355.     X    {
  356.     X    case 0:
  357.     X    break;
  358.     X    case 1:
  359.     X    case 2:
  360.     X    standout();
  361.     X    break;
  362.     X    }
  363.     X    mvprintw(line, col,  string);
  364.     X    switch (mode)
  365.     X    {
  366.     X    case 0:
  367.     X    break;
  368.     X    case 1:
  369.     X    case 2:
  370.     X    standend();
  371.     X    break;
  372.     X    }
  373.     X    refresh();
  374.     X    return;
  375.     X}
  376. SHAR_AND_ENJOY
  377. if test 1482 -ne "`wc -c < 'center.c'`"
  378. then
  379.     echo shar: error transmitting "'center.c'" '(should have been 1482 characters)'
  380. fi
  381. fi # end of overwriting check
  382. echo shar: extracting "'examp.c'" '(1557 characters)'
  383. if test -f 'examp.c'
  384. then
  385.     echo shar: will not over-write existing file "'examp.c'"
  386. else
  387. sed 's/^    X//' << \SHAR_AND_ENJOY > 'examp.c'
  388.     X#include <curses.h>
  389.     X#include "c_term.h"
  390.     X/*
  391.     X
  392.     X*/
  393.     X
  394.     Xmain()
  395.     X
  396.     X{
  397.     X    int num1, num2;
  398.     X    float fnum1, fnum2;
  399.     X    char HospNum[9];
  400.     X    char text[20];
  401.     X    static char *table[] =
  402.     X    {
  403.     X    "Number one",
  404.     X    "Number two",
  405.     X    "And even yet another"
  406.     X    };
  407.     X
  408.     X
  409.     X    init_term();
  410.     X    clear();
  411.     X
  412.     X    printw("Here are your choices -->");
  413.     X    num1 = pick_one(table, 3);
  414.     X    printw("<--\nNumber %d was chosen\n", num1);
  415.     X
  416.     X    move(2, 0);
  417.     X    printw("Here are your choices -->");
  418.     X    num1 = pick_one(table, 1);
  419.     X    printw("<--\nNumber %d was chosen\n", num1);
  420.     X
  421.     X    move(4, 0);
  422.     X    printw("Enter a string -->");
  423.     X    get_string(text, 15, 0);
  424.     X    printw("<--\nString is %s\n", text);
  425.     X
  426.     X    move(6, 0);
  427.     X    printw("yes or no ? -->");
  428.     X    num1 = get_bool(1);
  429.     X    printw(",");
  430.     X    num2 = get_bool(num1);
  431.     X    printw("<---\n");
  432.     X    printw("Booleans are %d, %d\n", num1, num2);
  433.     X
  434.     X    move(8, 0);
  435.     X    printw("Enter a number --->");
  436.     X    num1 = get_int(50, 4);
  437.     X    printw(",");
  438.     X    num2 = get_int(num1, 6);
  439.     X    printw("<---\n");
  440.     X    printw("Numbers were %d, %d\n", num1, num2);
  441.     X
  442.     X    move(10, 0);
  443.     X    printw("Enter a number --->");
  444.     X    fnum1 = get_float(50.0, 8, 5);
  445.     X    printw(",");
  446.     X    fnum2 = get_float(fnum1, 6, 2);
  447.     X    printw("<---\n");
  448.     X    printw("Numbers were %f, %f\n", fnum1, fnum2);
  449.     X
  450.     X    move(12, 0);
  451.     X    printw("Enter hospital number --->");
  452.     X    get_hosp_num(HospNum);
  453.     X    printw("<---\n");
  454.     X    printw("Number is %s\n", HospNum);
  455.     X
  456.     X    center(20, "This should be centered in line 20", 0);
  457.     X    center(21, "This should stand out in line 21", 1);
  458.     X    move(LINES - 1, 0);
  459.     X    refresh();
  460.     X    endwin();
  461.     X
  462.     X}
  463. SHAR_AND_ENJOY
  464. if test 1557 -ne "`wc -c < 'examp.c'`"
  465. then
  466.     echo shar: error transmitting "'examp.c'" '(should have been 1557 characters)'
  467. fi
  468. fi # end of overwriting check
  469. echo shar: extracting "'get_bool.c'" '(1643 characters)'
  470. if test -f 'get_bool.c'
  471. then
  472.     echo shar: will not over-write existing file "'get_bool.c'"
  473. else
  474. sed 's/^    X//' << \SHAR_AND_ENJOY > 'get_bool.c'
  475.     X#include <curses.h>
  476.     X#include <ctype.h>
  477.     X#include "c_term.h"
  478.     X
  479.     Xint get_bool(Default)
  480.     Xint Default;
  481.     X
  482.     X/*
  483.     X ---------------------------------------------------------------------------
  484.     X 
  485.     X   Last revision - 
  486.     X    6 January 1985 - GWS
  487.     X    Change to use curses
  488.     X
  489.     X    16 November 1984 - GWS
  490.     X    Ignore XON, XOFF
  491.     X
  492.     X     11 April 1984 - GWS
  493.     X 
  494.     X 
  495.     X   NAME
  496.     X     get_bool - "crash-proof" routine for terminal input of boolean
  497.     X 
  498.     X   SYNOPSIS
  499.     X    int get_bool(Default)
  500.     X    int Default;
  501.     X 
  502.     X   DESCRIPTION
  503.     X    This routine prompts and nudges the user through entry of a
  504.     X    boolean value.
  505.     X 
  506.     X   SEE ALSO
  507.     X 
  508.     X 
  509.     X   DIAGNOSTICS
  510.     X    none 
  511.     X 
  512.     X   BUGS
  513.     X    none known
  514.     X 
  515.     X   AUTHOR
  516.     X     George W. Sherouse
  517.     X     11 April 1984
  518.     X 
  519.     X ---------------------------------------------------------------------------
  520.     X*/
  521.     X
  522.     X{
  523.     X    int c;
  524.     X    int    val,
  525.     X    where_y,
  526.     X    where_x;
  527.     X
  528.     X    getyx(stdscr, where_y, where_x);
  529.     X    standout();
  530.     X
  531.     X    val = Default;
  532.     X    while (1)
  533.     X    {
  534.     X    if (val)
  535.     X        mvprintw(where_y, where_x, "yes");
  536.     X    else
  537.     X        mvprintw(where_y, where_x, "no ");
  538.     X    refresh();
  539.     X
  540.     X    switch (c = (getch() & 0177))
  541.     X    {
  542.     X#ifdef ABORT_CHAR
  543.     X    case ABORT_CHAR:
  544.     X        clear();
  545.     X        standend();
  546.     X        mvprintw(0, 0, "Program aborted at your request...");
  547.     X        move(LINES - 1, 0);
  548.     X        refresh();
  549.     X        endwin();
  550.     X        exit(0);
  551.     X        break;
  552.     X#endif ABORT_CHAR
  553.     X
  554.     X    case '\015':
  555.     X        standend();
  556.     X        if (val)
  557.     X        mvprintw(where_y, where_x, "yes");
  558.     X        else
  559.     X        mvprintw(where_y, where_x, "no ");
  560.     X        refresh();
  561.     X        return(val);
  562.     X        break;
  563.     X    case ' ':
  564.     X        val = !val;
  565.     X        break;
  566.     X    case 'y':
  567.     X    case 'Y':
  568.     X        val = 1;
  569.     X        break;
  570.     X    case 'n':
  571.     X    case 'N':
  572.     X        val = 0;
  573.     X        break;
  574.     X    case '\021':
  575.     X    case '\023':
  576.     X        break;
  577.     X    default:
  578.     X        fprintf(stderr, "%c", '\007');
  579.     X    }
  580.     X    }
  581.     X}
  582. SHAR_AND_ENJOY
  583. if test 1643 -ne "`wc -c < 'get_bool.c'`"
  584. then
  585.     echo shar: error transmitting "'get_bool.c'" '(should have been 1643 characters)'
  586. fi
  587. fi # end of overwriting check
  588. echo shar: extracting "'get_erase.c'" '(824 characters)'
  589. if test -f 'get_erase.c'
  590. then
  591.     echo shar: will not over-write existing file "'get_erase.c'"
  592. else
  593. sed 's/^    X//' << \SHAR_AND_ENJOY > 'get_erase.c'
  594.     X
  595.     X#include <stdio.h>
  596.     X#include <sgtty.h>
  597.     X#include <sys/ioctl.h>
  598.     X#include "c_term.h"
  599.     X
  600.     Xchar get_erase()
  601.     X/*
  602.     X ---------------------------------------------------------------------------
  603.     X 
  604.     X   Last revision - 
  605.     X     6 January 1985 - GWS
  606.     X 
  607.     X 
  608.     X   NAME
  609.     X     get_erase - get erase character for terminal
  610.     X 
  611.     X   SYNOPSIS
  612.     X    char get_erase()
  613.     X 
  614.     X   DESCRIPTION
  615.     X    The return character is the terminal's erase character.
  616.     X 
  617.     X   SEE ALSO
  618.     X 
  619.     X 
  620.     X   DIAGNOSTICS
  621.     X    Will exit(1) on any error. 
  622.     X 
  623.     X   BUGS
  624.     X    none known 
  625.     X 
  626.     X   AUTHOR
  627.     X     George W. Sherouse
  628.     X     3 January 1985
  629.     X 
  630.     X ---------------------------------------------------------------------------
  631.     X*/
  632.     X
  633.     X{
  634.     X    struct sgttyb params;
  635.     X    int ret;
  636.     X    int ioctl();
  637.     X
  638.     X    ret = ioctl(0, TIOCGETP, ¶ms);
  639.     X    if (ret == -1)
  640.     X    {
  641.     X        fprintf(stderr, "ioctl fail\n");
  642.     X        perror("get_erase");
  643.     X        exit(1);
  644.     X    }
  645.     X
  646.     X    return(params.sg_erase);
  647.     X}
  648. SHAR_AND_ENJOY
  649. if test 824 -ne "`wc -c < 'get_erase.c'`"
  650. then
  651.     echo shar: error transmitting "'get_erase.c'" '(should have been 824 characters)'
  652. fi
  653. fi # end of overwriting check
  654. echo shar: extracting "'get_float.c'" '(4515 characters)'
  655. if test -f 'get_float.c'
  656. then
  657.     echo shar: will not over-write existing file "'get_float.c'"
  658. else
  659. sed 's/^    X//' << \SHAR_AND_ENJOY > 'get_float.c'
  660.     X#include <stdio.h>
  661.     X#include <ctype.h>
  662.     X#include <curses.h>
  663.     X#include "c_term.h"
  664.     X
  665.     Xfloat get_float(Default, field_width, places)
  666.     Xfloat Default;
  667.     Xint field_width, places;
  668.     X
  669.     X/*
  670.     X ---------------------------------------------------------------------------
  671.     X 
  672.     X   Last revision - 
  673.     X    6 January 1985 - GWS
  674.     X    Make it use curses
  675.     X
  676.     X    16 November 1984 - GWS
  677.     X    Ignore XON, XOFF
  678.     X
  679.     X     11 April 1984 - GWS
  680.     X 
  681.     X 
  682.     X   NAME
  683.     X     get_float - "crash-proof" float from keyboard routine
  684.     X 
  685.     X   SYNOPSIS
  686.     X    float get_float(Default, field_width, places)
  687.     X    float Default;
  688.     X    int field_width, places;
  689.     X
  690.     X   DESCRIPTION
  691.     X    On a good day this routine will get a real value from the
  692.     X    keyboard and return it safely.  The terminal is placed in raw
  693.     X    mode and most non-digit values are beeped at and discarded.  Entry
  694.     X    is terminated by filling the field or by CR.  CR as first character
  695.     X    assumes Default.  ^X restarts.
  696.     X 
  697.     X   SEE ALSO
  698.     X 
  699.     X 
  700.     X   DIAGNOSTICS
  701.     X    none - cannot fail :-) 
  702.     X 
  703.     X   BUGS
  704.     X    Doesn't check for silly things like Default too big to fit in
  705.     X    field_width, etc.  Watch out for that minus sign!!
  706.     X    
  707.     X    Exponential notation is not supported.
  708.     X
  709.     X    This version does not let you erase over the decimal point if
  710.     X    the integer part of the field is already full.  This is not a
  711.     X    terrible hardship because you are free to ^X and start over,
  712.     X    but it really should be fixed.
  713.     X 
  714.     X   AUTHOR
  715.     X     George W. Sherouse
  716.     X     9 April 1984
  717.     X 
  718.     X ---------------------------------------------------------------------------
  719.     X*/
  720.     X
  721.     X{
  722.     X    int c;
  723.     X    float val;
  724.     X    int loop;
  725.     X    char line_buff[20];
  726.     X    char Format[80];
  727.     X    char pad;
  728.     X    int point, frac_count;
  729.     X    int count;
  730.     X    int int_part;
  731.     X    int    where_x,
  732.     X        where_y,
  733.     X        x,
  734.     X        y;
  735.     X
  736.     X    void f_clean_up();
  737.     X
  738.     X    pad = ' ';
  739.     X    point = 0;
  740.     X    frac_count = 0 ;
  741.     X
  742.     X    getyx(stdscr, where_y, where_x);
  743.     X    standout();
  744.     X
  745.     X    for (loop = 0; loop < field_width; loop++)
  746.     X        printw(" ");
  747.     X
  748.     X    move(where_y, where_x);
  749.     X    refresh();
  750.     X
  751.     X    sprintf(Format, "%%%d.%df", field_width, places);
  752.     X    printw(Format, Default);
  753.     X    move(where_y, where_x);
  754.     X    refresh();
  755.     X    for (loop = 0; loop <= field_width; loop++)
  756.     X        line_buff[loop] = 0;
  757.     X
  758.     X    count = 0;
  759.     X    int_part = field_width - places - 1;
  760.     X    while (1)
  761.     X    {
  762.     X        if (!point && count == int_part)
  763.     X        {
  764.     X        printw(".");
  765.     X        line_buff[count++] = '.';
  766.     X        point++;
  767.     X        continue;
  768.     X        }
  769.     X        refresh();
  770.     X
  771.     X        c = (getch() & 0x7f);
  772.     X        switch(c)
  773.     X        {
  774.     X#ifdef ABORT_CHAR
  775.     X        case ABORT_CHAR:
  776.     X        clear();
  777.     X        standend();
  778.     X        mvprintw(0, 0, "Program aborted at your request...");
  779.     X        move(LINES -1 , 0);
  780.     X        refresh();
  781.     X        endwin();
  782.     X        exit(1);
  783.     X        break;
  784.     X#endif ABORT_CHAR
  785.     X
  786.     X        case '\r':
  787.     X        if (count && line_buff[count - 1] != '-')
  788.     X        {
  789.     X            sscanf(line_buff, "%f", &val);
  790.     X            f_clean_up(where_y, where_x, Format, val);
  791.     X            return(val);
  792.     X        }
  793.     X        else
  794.     X        {
  795.     X            f_clean_up(where_y, where_x, Format, Default);
  796.     X            return(Default);
  797.     X        }
  798.     X        break;
  799.     X        case '\030':
  800.     X        move(where_y, where_x);
  801.     X        for (loop = 0; loop < field_width; loop++)
  802.     X            line_buff[loop] = 0;
  803.     X        count = frac_count = point = 0;
  804.     X        printw(Format, Default);
  805.     X        move(where_y, where_x);
  806.     X        break;
  807.     X        case '.':
  808.     X        if (!point)
  809.     X        {
  810.     X            if (!count)
  811.     X            {
  812.     X            for (loop = 0; loop < field_width; loop++)
  813.     X                printw("%c", pad);
  814.     X            move(where_y, where_x);
  815.     X            for (loop = 0; loop < field_width; loop++)
  816.     X                line_buff[loop] = 0;
  817.     X            }
  818.     X            printw(".");
  819.     X            line_buff[count++] = '.';
  820.     X            point++;
  821.     X            break;
  822.     X        }
  823.     X        case '\021':
  824.     X        case '\023':
  825.     X        break;
  826.     X        default:
  827.     X        if (c == erase_char && count)
  828.     X        {
  829.     X            getyx(stdscr, y, x);
  830.     X            move(y, x - 1);
  831.     X            printw("%c", pad);
  832.     X            move(y, x - 1);
  833.     X            if (point)
  834.     X            {
  835.     X            if (frac_count)
  836.     X                frac_count--;
  837.     X            else
  838.     X                point--;
  839.     X            }
  840.     X            line_buff[--count] = 0;
  841.     X            break;
  842.     X        }
  843.     X
  844.     X        if (!count && c == '-')
  845.     X        {
  846.     X            for (loop = 0; loop < field_width; loop++)
  847.     X            printw("%c", pad);
  848.     X            move(where_y, where_x);
  849.     X            for (loop = 0; loop < field_width; loop++)
  850.     X                line_buff[loop] = 0;
  851.     X
  852.     X            line_buff[count++] = (char) c;
  853.     X            printw("-");
  854.     X            break;
  855.     X        }
  856.     X
  857.     X        if (isdigit(c) && count < field_width && frac_count < places)
  858.     X        {
  859.     X            if (!count)
  860.     X            {
  861.     X            for (loop = 0; loop < field_width; loop++)
  862.     X                printw("%c", pad);
  863.     X            move(where_y, where_x);
  864.     X            for (loop = 0; loop < field_width; loop++)
  865.     X                line_buff[loop] = 0;
  866.     X            }
  867.     X            printw("%c", c);
  868.     X            line_buff[count++] = (char) c;
  869.     X            if (point)
  870.     X            frac_count++;
  871.     X        }
  872.     X        else
  873.     X            fprintf(stderr, "%c", '\007');
  874.     X        }
  875.     X    }
  876.     X}
  877.     X
  878.     Xvoid f_clean_up(where_y, where_x, Format, val)
  879.     Xint where_y, where_x;
  880.     Xchar *Format;
  881.     Xfloat val;
  882.     X
  883.     X{
  884.     X    int loop;
  885.     X
  886.     X    standend();
  887.     X    move(where_y, where_x);
  888.     X    printw(Format, val);
  889.     X
  890.     X    refresh();
  891.     X}
  892. SHAR_AND_ENJOY
  893. if test 4515 -ne "`wc -c < 'get_float.c'`"
  894. then
  895.     echo shar: error transmitting "'get_float.c'" '(should have been 4515 characters)'
  896. fi
  897. fi # end of overwriting check
  898. echo shar: extracting "'get_hosp_num.c'" '(2331 characters)'
  899. if test -f 'get_hosp_num.c'
  900. then
  901.     echo shar: will not over-write existing file "'get_hosp_num.c'"
  902. else
  903. sed 's/^    X//' << \SHAR_AND_ENJOY > 'get_hosp_num.c'
  904.     X#include <curses.h>
  905.     X#include <ctype.h>
  906.     X#include "c_term.h"
  907.     X
  908.     Xvoid get_hosp_num (HospNum)
  909.     Xchar *HospNum;
  910.     X
  911.     X/*
  912.     X ---------------------------------------------------------------------------
  913.     X 
  914.     X   Last revision - 
  915.     X    6 January 1985 - GWS
  916.     X    Change it to use curses
  917.     X
  918.     X    16 November 1984 - GWS
  919.     X    Ignore XON, XOFF
  920.     X
  921.     X     11 April 1984 - GWS
  922.     X 
  923.     X 
  924.     X   NAME
  925.     X     get_hosp_num - "crash-proof" routine for terminal input of ##-##-##
  926.     X 
  927.     X   SYNOPSIS
  928.     X    void get_hosp_num(HospNum)
  929.     X    char *HospNum;
  930.     X 
  931.     X   DESCRIPTION
  932.     X    This routine prompts and nudges the user through entry of a
  933.     X    hospital number in the proper format.
  934.     X 
  935.     X   SEE ALSO
  936.     X 
  937.     X 
  938.     X   DIAGNOSTICS
  939.     X    none 
  940.     X 
  941.     X   BUGS
  942.     X    Doesn't do any validity checking on the number, only the format. 
  943.     X 
  944.     X   AUTHOR
  945.     X     George W. Sherouse
  946.     X     9 April 1984
  947.     X 
  948.     X ---------------------------------------------------------------------------
  949.     X*/
  950.     X
  951.     X{
  952.     X    int c;
  953.     X    int count,
  954.     X       where_y,
  955.     X    where_x,
  956.     X    x,
  957.     X    y;
  958.     X
  959.     X    getyx(stdscr, where_y, where_x);
  960.     X    standout();
  961.     X
  962.     X    printw("  -  -  ");
  963.     X    move(where_y, where_x);
  964.     X    refresh();
  965.     X
  966.     X    count = 0;
  967.     X    while (1)
  968.     X    {
  969.     X    switch (count)
  970.     X    {
  971.     X    case 2:
  972.     X    case 5:
  973.     X        printw("-");
  974.     X        HospNum[count++] = '-';
  975.     X        break;
  976.     X    default:
  977.     X        switch (c = (getchar() & 0177))
  978.     X        {
  979.     X#ifdef ABORT_CHAR
  980.     X        case ABORT_CHAR:
  981.     X        clear();
  982.     X        standend();
  983.     X        mvprintw(0, 0, "Program aborted at your request...");
  984.     X        move(LINES - 1, 0);
  985.     X        refresh();
  986.     X        endwin();
  987.     X        exit(0);
  988.     X        break;
  989.     X#endif ABORT_CHAR
  990.     X
  991.     X        case '\015':
  992.     X        if (count == 8)
  993.     X        {
  994.     X            HospNum[8] = (char) 0;
  995.     X            standend();
  996.     X            mvprintw(where_y, where_x, HospNum);
  997.     X            refresh();
  998.     X            return;
  999.     X        }
  1000.     X        else
  1001.     X        {
  1002.     X            fprintf(stderr, "%c", '\007');
  1003.     X            break;
  1004.     X        }
  1005.     X        case 030:
  1006.     X        mvprintw(where_y, where_x, "  -  -  ");
  1007.     X        move(where_y, where_x);
  1008.     X        count = 0;
  1009.     X        break;
  1010.     X        case '\021':
  1011.     X        case '\023':
  1012.     X        break;
  1013.     X        default:
  1014.     X        if (c == erase_char && count)
  1015.     X        {
  1016.     X            switch (count)
  1017.     X            {
  1018.     X            case 3:
  1019.     X            case 6:
  1020.     X            getyx(stdscr, y, x);
  1021.     X            move(y, x - 1);
  1022.     X            count--;
  1023.     X            case 1:
  1024.     X            case 2:
  1025.     X            case 4:
  1026.     X            case 5:
  1027.     X            case 7:
  1028.     X            case 8:
  1029.     X            getyx(stdscr, y, x);
  1030.     X            mvprintw(y, x - 1, " ");
  1031.     X            move(y, x - 1);
  1032.     X            HospNum[--count] = 0;
  1033.     X            break;
  1034.     X            }
  1035.     X            break;
  1036.     X        }
  1037.     X
  1038.     X        if (isdigit(c) && count < 8)
  1039.     X        {
  1040.     X            printw("%c", c);
  1041.     X            HospNum[count++] = (char) c;
  1042.     X        }
  1043.     X        else
  1044.     X            fprintf(stderr, "%c", '\007');
  1045.     X        }
  1046.     X    }
  1047.     X    refresh();
  1048.     X    }
  1049.     X}
  1050. SHAR_AND_ENJOY
  1051. if test 2331 -ne "`wc -c < 'get_hosp_num.c'`"
  1052. then
  1053.     echo shar: error transmitting "'get_hosp_num.c'" '(should have been 2331 characters)'
  1054. fi
  1055. fi # end of overwriting check
  1056. echo shar: extracting "'get_int.c'" '(3386 characters)'
  1057. if test -f 'get_int.c'
  1058. then
  1059.     echo shar: will not over-write existing file "'get_int.c'"
  1060. else
  1061. sed 's/^    X//' << \SHAR_AND_ENJOY > 'get_int.c'
  1062.     X#include <curses.h>
  1063.     X#include <ctype.h>
  1064.     X#include "c_term.h"
  1065.     X
  1066.     Xint get_int(Default, field_width)
  1067.     Xint Default, field_width;
  1068.     X
  1069.     X/*
  1070.     X ---------------------------------------------------------------------------
  1071.     X 
  1072.     X   Last revision - 
  1073.     X    6 January 1985 - GWS
  1074.     X    Change to use curses
  1075.     X
  1076.     X    16 November 1984 - GWS
  1077.     X    Ignore XON, XOFF
  1078.     X
  1079.     X     11 April 1984 - GWS
  1080.     X 
  1081.     X 
  1082.     X   NAME
  1083.     X     get_int - "crash-proof" integer from keyboard routine
  1084.     X 
  1085.     X   SYNOPSIS
  1086.     X    int get_int(Default, field_width)
  1087.     X    int Default, field_width;
  1088.     X 
  1089.     X   DESCRIPTION
  1090.     X    On a good day this routine will get an integer value from the
  1091.     X    keyboard and return it safely.  The terminal is placed in raw
  1092.     X    mode and most non-digit values are beeped at and discarded.  Entry
  1093.     X    is terminated by filling the field or by CR.  CR as first character
  1094.     X    assumes Default.  ^X restarts.
  1095.     X 
  1096.     X   SEE ALSO
  1097.     X 
  1098.     X   DIAGNOSTICS
  1099.     X    none - cannot fail :-) 
  1100.     X 
  1101.     X   BUGS
  1102.     X    Doesn't check for silly things like Default too big to fit in
  1103.     X    field_width, etc.  Let's be particularly careful out there.
  1104.     X 
  1105.     X   AUTHOR
  1106.     X     George W. Sherouse
  1107.     X     6 April 1984
  1108.     X 
  1109.     X ---------------------------------------------------------------------------
  1110.     X*/
  1111.     X
  1112.     X{
  1113.     X    int c, val;
  1114.     X    int loop;
  1115.     X    char line_buff[20];
  1116.     X    char Format[80];
  1117.     X    char pad;
  1118.     X    int count;
  1119.     X    int    where_x,
  1120.     X        where_y,
  1121.     X        x,
  1122.     X        y;
  1123.     X
  1124.     X    void clean_up();
  1125.     X
  1126.     X    pad = ' ';
  1127.     X    getyx(stdscr, where_y, where_x);
  1128.     X    standout();
  1129.     X
  1130.     X    for (loop = 0; loop < field_width; loop++)
  1131.     X        printw(" ");
  1132.     X
  1133.     X    sprintf(Format, "%%%dd", field_width);
  1134.     X    mvprintw(where_y, where_x, Format, Default);
  1135.     X    move(where_y, where_x);
  1136.     X    refresh();
  1137.     X    for (loop = 0; loop <= field_width; loop++)
  1138.     X        line_buff[loop] = 0;
  1139.     X
  1140.     X    count = 0;
  1141.     X    while (1)
  1142.     X    {
  1143.     X        switch (c = (getch() & 0177))
  1144.     X        {
  1145.     X#ifdef ABORT_CHAR
  1146.     X        case ABORT_CHAR:
  1147.     X        clear();
  1148.     X        standend();
  1149.     X        mvprintw(0, 0, "Program aborted at your request...");
  1150.     X        move(LINES - 1, 0);
  1151.     X        refresh();
  1152.     X        endwin();
  1153.     X        exit(0);
  1154.     X        break;
  1155.     X#endif ABORT_CHAR
  1156.     X
  1157.     X        case '\015':
  1158.     X        if (count && line_buff[count - 1] != '-')
  1159.     X        {
  1160.     X            sscanf(line_buff, "%d", &val);
  1161.     X            clean_up(where_y, where_x, Format, val);
  1162.     X            return(val);
  1163.     X        }
  1164.     X        else
  1165.     X        {
  1166.     X            clean_up(where_y, where_x, Format, Default);
  1167.     X            return(Default);
  1168.     X        }
  1169.     X        break;
  1170.     X        case 030:
  1171.     X        for (loop = 0; loop < field_width; loop++)
  1172.     X            line_buff[loop] = 0;
  1173.     X        count = 0;
  1174.     X        mvprintw(where_y, where_x, Format, Default);
  1175.     X        move(where_y, where_x);
  1176.     X        break;
  1177.     X        case '\021':
  1178.     X        case '\023':
  1179.     X        break;
  1180.     X        default:
  1181.     X        if (c == erase_char && count)
  1182.     X        {
  1183.     X            getyx(stdscr, y, x);
  1184.     X            mvprintw(y, x - 1, "%c", pad);
  1185.     X            move(y, x - 1);
  1186.     X            line_buff[--count] = 0;
  1187.     X            break;
  1188.     X        }
  1189.     X
  1190.     X        if (!count && c == '-')
  1191.     X        {
  1192.     X            for (loop = 0; loop < field_width; loop++)
  1193.     X            printw("%c", pad);
  1194.     X            move(where_y, where_x);
  1195.     X            for (loop = 0; loop < field_width; loop++)
  1196.     X                line_buff[loop] = 0;
  1197.     X
  1198.     X            line_buff[count++] = (char) c;
  1199.     X            printw("-");
  1200.     X            break;
  1201.     X        }
  1202.     X
  1203.     X        if (isdigit(c) && count < field_width)
  1204.     X        {
  1205.     X            if (!count)
  1206.     X            {
  1207.     X            for (loop = 0; loop < field_width; loop++)
  1208.     X                printw("%c", pad);
  1209.     X            move(where_y, where_x);
  1210.     X            for (loop = 0; loop < field_width; loop++)
  1211.     X                line_buff[loop] = 0;
  1212.     X            }
  1213.     X            printw("%c", c);
  1214.     X            line_buff[count++] = (char) c;
  1215.     X        }
  1216.     X        else
  1217.     X            fprintf(stderr, "%c", '\007');
  1218.     X        }
  1219.     X    refresh();
  1220.     X    }
  1221.     X}
  1222.     X
  1223.     Xvoid clean_up(where_y, where_x, Format, val)
  1224.     Xint where_y, where_x;
  1225.     Xchar *Format;
  1226.     Xint val;
  1227.     X
  1228.     X{
  1229.     X    int loop;
  1230.     X
  1231.     X    standend();
  1232.     X    mvprintw(where_y, where_x, Format, val);
  1233.     X    refresh();
  1234.     X}
  1235. SHAR_AND_ENJOY
  1236. if test 3386 -ne "`wc -c < 'get_int.c'`"
  1237. then
  1238.     echo shar: error transmitting "'get_int.c'" '(should have been 3386 characters)'
  1239. fi
  1240. fi # end of overwriting check
  1241. echo shar: extracting "'get_string.c'" '(2357 characters)'
  1242. if test -f 'get_string.c'
  1243. then
  1244.     echo shar: will not over-write existing file "'get_string.c'"
  1245. else
  1246. sed 's/^    X//' << \SHAR_AND_ENJOY > 'get_string.c'
  1247.     X#include <curses.h>
  1248.     X#include <ctype.h>
  1249.     X#include "c_term.h"
  1250.     X
  1251.     Xvoid get_string(string, size, nullOK)
  1252.     Xchar *string;
  1253.     Xint size;
  1254.     Xint nullOK;
  1255.     X
  1256.     X/*
  1257.     X ---------------------------------------------------------------------------
  1258.     X 
  1259.     X   Last revision - 
  1260.     X    6 January 1985 - GWS
  1261.     X    Change to use curses
  1262.     X
  1263.     X    16 November 1984 - GWS
  1264.     X    Ignore XON, XOFF
  1265.     X
  1266.     X     11 April 1984 - GWS
  1267.     X 
  1268.     X 
  1269.     X   NAME
  1270.     X     get_string - "crash-proof" routine for terminal input of string
  1271.     X 
  1272.     X   SYNOPSIS
  1273.     X    void get_string(string, size, nullOK)
  1274.     X    char *string;
  1275.     X    int size;
  1276.     X    int nullOK;
  1277.     X 
  1278.     X   DESCRIPTION
  1279.     X    This routine prompts and nudges the user through entry of a
  1280.     X    character string.  'Size' is the number of characters in'string'.
  1281.     X    'String' should therefore be dimensioned to size + 1.
  1282.     X    'NullOK' is a boolean that tells us whether a null string is
  1283.     X    acceptable.
  1284.     X 
  1285.     X   SEE ALSO
  1286.     X 
  1287.     X 
  1288.     X   DIAGNOSTICS
  1289.     X    none 
  1290.     X 
  1291.     X   BUGS
  1292.     X    none known
  1293.     X 
  1294.     X   AUTHOR
  1295.     X     George W. Sherouse
  1296.     X     11 April 1984
  1297.     X 
  1298.     X ---------------------------------------------------------------------------
  1299.     X*/
  1300.     X
  1301.     X{
  1302.     X    int c;
  1303.     X    int loop;
  1304.     X    int count,
  1305.     X    where_x,
  1306.     X    where_y,
  1307.     X    x,
  1308.     X    y;
  1309.     X    char    Format[30];
  1310.     X
  1311.     X    standout();
  1312.     X    getyx(stdscr, where_y, where_x);
  1313.     X
  1314.     X    for (loop = 0; loop < size; loop++)
  1315.     X    {
  1316.     X    printw(" ");
  1317.     X    string[loop] = (char) 0;
  1318.     X    }
  1319.     X    string[size] = (char) 0;
  1320.     X    move(where_y, where_x);
  1321.     X    refresh();
  1322.     X
  1323.     X    count = 0;
  1324.     X    while (1)
  1325.     X    {
  1326.     X    switch (c = (getch() & 0177))
  1327.     X    {
  1328.     X#ifdef ABORT_CHAR
  1329.     X    case ABORT_CHAR:
  1330.     X        clear();
  1331.     X        standend();
  1332.     X        mvprintw(0, 0, "Program aborted at your request...");
  1333.     X        move(LINES - 1, 0);
  1334.     X        refresh();
  1335.     X        endwin();
  1336.     X        exit(0);
  1337.     X        break;
  1338.     X#endif ABORT_CHAR
  1339.     X
  1340.     X    case '\015':
  1341.     X        if (count || nullOK)
  1342.     X        {
  1343.     X        standend();
  1344.     X        sprintf(Format, "%%-%ds", size);
  1345.     X        mvprintw(where_y, where_x, Format, string);
  1346.     X        refresh();
  1347.     X        return;
  1348.     X        }
  1349.     X        else
  1350.     X        {
  1351.     X        fprintf(stderr, "%c", '\007');
  1352.     X        break;
  1353.     X        }
  1354.     X    case '\030':
  1355.     X        while (count)
  1356.     X        {
  1357.     X        string[--count] = (char) 0;
  1358.     X        getyx(stdscr, y, x);
  1359.     X        mvprintw(y, x-1, " ");
  1360.     X        move(y, x - 1);
  1361.     X        }
  1362.     X        break;
  1363.     X    case '\021':
  1364.     X    case '\023':
  1365.     X        break;
  1366.     X    default:
  1367.     X        if (count && c == erase_char)
  1368.     X        {
  1369.     X        getyx(stdscr, y, x);
  1370.     X        mvprintw(y, x-1, " ");
  1371.     X        move(y, x - 1);
  1372.     X        string[--count] = (char) 0;
  1373.     X        break;
  1374.     X        }
  1375.     X
  1376.     X        if (isprint(c) && count < size)
  1377.     X        {
  1378.     X        printw("%c", c);
  1379.     X        string[count++] = c;
  1380.     X        break;
  1381.     X        }
  1382.     X
  1383.     X        fprintf(stderr, "%c", '\007');
  1384.     X    }
  1385.     X    refresh();
  1386.     X    }
  1387.     X}
  1388. SHAR_AND_ENJOY
  1389. if test 2357 -ne "`wc -c < 'get_string.c'`"
  1390. then
  1391.     echo shar: error transmitting "'get_string.c'" '(should have been 2357 characters)'
  1392. fi
  1393. fi # end of overwriting check
  1394. echo shar: extracting "'init_term.c'" '(690 characters)'
  1395. if test -f 'init_term.c'
  1396. then
  1397.     echo shar: will not over-write existing file "'init_term.c'"
  1398. else
  1399. sed 's/^    X//' << \SHAR_AND_ENJOY > 'init_term.c'
  1400.     X#include <curses.h>
  1401.     X#include "c_term.h"
  1402.     X
  1403.     Xvoid init_term()
  1404.     X/*
  1405.     X ---------------------------------------------------------------------------
  1406.     X 
  1407.     X   Last revision - 
  1408.     X     6 January 1985 - GWS
  1409.     X 
  1410.     X 
  1411.     X   NAME
  1412.     X     init_term - initialize curses and c_term
  1413.     X 
  1414.     X   SYNOPSIS
  1415.     X    void init_term()
  1416.     X 
  1417.     X   DESCRIPTION
  1418.     X    This routine must be called before use of the c_term
  1419.     X    idiot-proof input library.  It includes a call to initscr
  1420.     X    to initialize curses.
  1421.     X 
  1422.     X   DIAGNOSTICS
  1423.     X 
  1424.     X 
  1425.     X   FILES
  1426.     X 
  1427.     X 
  1428.     X   SEE ALSO
  1429.     X    curses(3X) 
  1430.     X 
  1431.     X   BUGS
  1432.     X 
  1433.     X 
  1434.     X   AUTHOR
  1435.     X     George W. Sherouse
  1436.     X     6 January 1985
  1437.     X 
  1438.     X ---------------------------------------------------------------------------
  1439.     X*/
  1440.     X
  1441.     X{
  1442.     X    erase_char = get_erase();
  1443.     X    initscr();
  1444.     X    raw();
  1445.     X    noecho();
  1446.     X}
  1447. SHAR_AND_ENJOY
  1448. if test 690 -ne "`wc -c < 'init_term.c'`"
  1449. then
  1450.     echo shar: error transmitting "'init_term.c'" '(should have been 690 characters)'
  1451. fi
  1452. fi # end of overwriting check
  1453. echo shar: extracting "'pick_one.c'" '(2511 characters)'
  1454. if test -f 'pick_one.c'
  1455. then
  1456.     echo shar: will not over-write existing file "'pick_one.c'"
  1457. else
  1458. sed 's/^    X//' << \SHAR_AND_ENJOY > 'pick_one.c'
  1459.     X#include <curses.h>
  1460.     X#include <ctype.h>
  1461.     X#include <strings.h>
  1462.     X#include "c_term.h"
  1463.     X
  1464.     Xint pick_one(ChoiceList, ChoiceCount)
  1465.     Xchar **ChoiceList;
  1466.     Xint ChoiceCount;
  1467.     X
  1468.     X/*
  1469.     X ---------------------------------------------------------------------------
  1470.     X 
  1471.     X   Last revision - 
  1472.     X    6 January 1985 - GWS
  1473.     X    Change to use curses
  1474.     X
  1475.     X    16 November 1984 - GWS
  1476.     X    Ignore XON, XOFF
  1477.     X
  1478.     X     12 April 1984 - GWS
  1479.     X 
  1480.     X 
  1481.     X   NAME
  1482.     X     pick_one - "crash-proof" routine for picking one of a list of
  1483.     X          list of strings
  1484.     X 
  1485.     X   SYNOPSIS
  1486.     X    int pick_one(ChoiceList, ChoiceCount)
  1487.     X    char **ChoiceList;
  1488.     X    int ChoiceCount;
  1489.     X 
  1490.     X   DESCRIPTION
  1491.     X    This routine prompts and nudges the user through selection of a
  1492.     X    string from a table of strings - useful for choosing an item
  1493.     X    from a menu for instance.  The options are displayed one at a
  1494.     X    time.  The current item is selected by pressing return.  The
  1495.     X    space bar advances, the up-arrow backs up.  The return
  1496.     X    value of the function is the index of the chosen string.
  1497.     X 
  1498.     X   SEE ALSO
  1499.     X 
  1500.     X 
  1501.     X   DIAGNOSTICS
  1502.     X    none 
  1503.     X 
  1504.     X   BUGS
  1505.     X    none known
  1506.     X 
  1507.     X   AUTHOR
  1508.     X     George W. Sherouse
  1509.     X     11 April 1984
  1510.     X 
  1511.     X ---------------------------------------------------------------------------
  1512.     X*/
  1513.     X
  1514.     X{
  1515.     X    int c;
  1516.     X    int val;
  1517.     X    int biggest;
  1518.     X    int temp;
  1519.     X    int loop;
  1520.     X    int    where_y,
  1521.     X    where_x;
  1522.     X    char Format[80];
  1523.     X
  1524.     X    int strlen();
  1525.     X
  1526.     X/*
  1527.     XIn the silly case where there is only one choice, just print it
  1528.     Xand return the index 0.
  1529.     X*/
  1530.     X    if (ChoiceCount == 1)
  1531.     X    {
  1532.     X    printw("%s", ChoiceList[0]);
  1533.     X    return(0);
  1534.     X    }
  1535.     X/*
  1536.     XFind the longest string in the bunch
  1537.     X*/
  1538.     X    biggest = strlen(ChoiceList[0]);
  1539.     X    for (loop = 1; loop < ChoiceCount; loop++)
  1540.     X    if ((temp = strlen(ChoiceList[loop])) > biggest)
  1541.     X        biggest = temp;
  1542.     X
  1543.     X    getyx(stdscr, where_y, where_x);
  1544.     X    standout();
  1545.     X    for (loop = 0; loop < biggest; loop++)
  1546.     X    printw(" ");
  1547.     X
  1548.     X    sprintf(Format, "%%-%ds", biggest);
  1549.     X
  1550.     X    val = 0;
  1551.     X    while (1)
  1552.     X    {
  1553.     X    mvprintw(where_y, where_x, Format, ChoiceList[val]);
  1554.     X    refresh();
  1555.     X
  1556.     X    switch (c = (getch() & 0177))
  1557.     X    {
  1558.     X#ifdef ABORT_CHAR
  1559.     X    case ABORT_CHAR:
  1560.     X        clear();
  1561.     X        standend();
  1562.     X        mvprintw(0, 0, "Program aborted at your request...");
  1563.     X        move(LINES - 1, 0);
  1564.     X        refresh();
  1565.     X        endwin();
  1566.     X        exit(0);
  1567.     X        break;
  1568.     X#endif ABORT_CHAR
  1569.     X
  1570.     X    case '\015':
  1571.     X        standend();
  1572.     X        mvprintw(where_y, where_x, Format, ChoiceList[val]);
  1573.     X        refresh();
  1574.     X        return(val);
  1575.     X    case ' ':
  1576.     X        if (++val == ChoiceCount)
  1577.     X        val = 0;
  1578.     X        break;
  1579.     X    case '^':
  1580.     X        if (--val < 0)
  1581.     X        val = ChoiceCount - 1;
  1582.     X        break;
  1583.     X    case '\021':
  1584.     X    case '\023':
  1585.     X        break;
  1586.     X    default:
  1587.     X        fprintf(stderr, "%c", '\007');
  1588.     X    }
  1589.     X    }
  1590.     X}
  1591. SHAR_AND_ENJOY
  1592. if test 2511 -ne "`wc -c < 'pick_one.c'`"
  1593. then
  1594.     echo shar: error transmitting "'pick_one.c'" '(should have been 2511 characters)'
  1595. fi
  1596. fi # end of overwriting check
  1597. #    End of shell archive
  1598. exit 0
  1599.  
  1600.  
  1601.